package com.ruoyi.project.price.service.impl;

import java.math.BigDecimal;
import java.util.List;

import cn.hutool.core.lang.Snowflake;
import com.ruoyi.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.price.mapper.BinsAccountMapper;
import com.ruoyi.project.price.domain.BinsAccount;
import com.ruoyi.project.price.service.IBinsAccountService;

/**
 * acountService业务层处理
 * 
 * @author admin
 * @date 2025-04-02
 */
@Service
public class BinsAccountServiceImpl implements IBinsAccountService 
{
    private Logger logger = LoggerFactory.getLogger(BinsAccountServiceImpl.class);
    @Autowired
    private BinsAccountMapper binsAccountMapper;
    @Autowired
    private Snowflake snowflake;

    /**
     * 查询acount
     * 
     * @param id acount主键
     * @return acount
     */
    @Override
    public BinsAccount selectBinsAccountById(Long id)
    {
        return binsAccountMapper.selectBinsAccountById(id);
    }

    /**
     * 查询acount
     *
     * @param id acount主键
     * @return acount
     */
    @Override
    public BinsAccount selectBinsAccountByUserId(String userId)
    {
        return binsAccountMapper.selectBinsAccountByUserId(userId);
    }

    /**
     * 查询acount列表
     * 
     * @param binsAccount acount
     * @return acount
     */
    @Override
    public List<BinsAccount> selectBinsAccountList(BinsAccount binsAccount)
    {
        List<BinsAccount> list = binsAccountMapper.selectBinsAccountList(binsAccount);
        if (list!=null && list.size()>0){
            for (BinsAccount account:list){
                BigDecimal totalAmount = account.getTotalAmount();
                if (totalAmount!=null) {
                    logger.info("totalAmount:{}",totalAmount.setScale(2, BigDecimal.ROUND_HALF_UP));
                    account.setTotalAmount(totalAmount.setScale(2, BigDecimal.ROUND_HALF_UP));
                }
            }
        }
        return list;
    }

    /**
     * 新增acount
     * 
     * @param binsAccount acount
     * @return 结果
     */
    @Override
    public int insertBinsAccount(BinsAccount binsAccount)
    {
        binsAccount.setCreateTime(DateUtils.getNowDate());
        if (binsAccount.getUserId()!=null){
            BinsAccount binsAccount_slt = binsAccountMapper.selectBinsAccountByUserId(binsAccount.getUserId());
            if (binsAccount_slt!=null){
                binsAccount.setId(binsAccount_slt.getId());
                return 1;
            }
        }
        return binsAccountMapper.insertBinsAccount(binsAccount);
    }

    /**
     * 修改acount
     * 
     * @param binsAccount acount
     * @return 结果
     */
    @Override
    public int updateBinsAccount(BinsAccount binsAccount)
    {
        binsAccount.setUpdateTime(DateUtils.getNowDate());
        return binsAccountMapper.updateBinsAccount(binsAccount);
    }

    /**
     * 批量删除acount
     * 
     * @param ids 需要删除的acount主键
     * @return 结果
     */
    @Override
    public int deleteBinsAccountByIds(Long[] ids)
    {
        return binsAccountMapper.deleteBinsAccountByIds(ids);
    }

    /**
     * 删除acount信息
     * 
     * @param id acount主键
     * @return 结果
     */
    @Override
    public int deleteBinsAccountById(Long id)
    {
        return binsAccountMapper.deleteBinsAccountById(id);
    }
}
